package com.example.ibsp_demo.controller.admin;

import com.example.ibsp_demo.ApiMessage.ApiMessage;
import com.example.ibsp_demo.pojo.entity.admin.Activity;
import com.example.ibsp_demo.pojo.entity.content.Content;
import com.example.ibsp_demo.pojo.entity.content.Partition;
import com.example.ibsp_demo.pojo.entity.message.SendBack;
import com.example.ibsp_demo.pojo.entity.message.UserFeedback;
import com.example.ibsp_demo.pojo.entity.user.User;
import com.example.ibsp_demo.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    //1.查询用户
    @GetMapping("/allUser")
    public ApiMessage<List<User>> allUser() {
        List<User> users = adminService.allUsers();
        return ApiMessage.success(users);
    }
    @GetMapping("/queryUser/{uid}")
    public ApiMessage<List<User>> queryUser(@PathVariable("uid") Integer uid ) {
        List<User> users = adminService.queryUsers(uid);
        return ApiMessage.success(users);
    }
    // 2.封禁用户
    @PutMapping("/unBanUser")
    public ApiMessage<String> unBanUser(@RequestParam Integer uid, @RequestParam Integer aid) {
        adminService.unBanUser(uid, aid);
        return ApiMessage.success("用户解封成功");
    }

    @PutMapping("/banUser")
    public ApiMessage<String> banUser(@RequestParam Integer uid, @RequestParam Integer aid) {
        adminService.banUser(uid, aid);
        return ApiMessage.success("用户封禁成功");
    }
    // 3.查询博客
    @GetMapping("/allBlog")
    public ApiMessage<List<Content>> allBlog() {
        List<Content> blogs = adminService.allContent();
        return ApiMessage.success(blogs);
    }

    @GetMapping("/queryBlog/{ctid}")
    public ApiMessage<List<Content>> queryBlog(@PathVariable("ctid") Integer ctid) {
        List<Content> blogs = adminService.queryContent(ctid);
        return ApiMessage.success(blogs);
    }
    // 4.发布活动
    @GetMapping("/allActivity")
    public ApiMessage<List<Activity>> allActivity() {
        List<Activity> activities = adminService.allActivity();
        return ApiMessage.success(activities);
    }

    @PostMapping("/publishActivity")
    public ApiMessage<String> publishActivity(@Validated @RequestBody Activity activity) {
        adminService.publishActivity(activity);
        return ApiMessage.success("活动发布成功");
    }

    @PostMapping("/deleteActivity")
    public ApiMessage<String> deleteActivity(@RequestParam Integer id) {
        adminService.deleteActivity(id);
        return ApiMessage.success("活动删除成功");
    }
    // 5.审核博客
    //通过博客
    @PutMapping("/goContent/{ctid}")
    public ApiMessage<String> goContent(@PathVariable("ctid") Integer ctid) {
        adminService.goContent(ctid);
        return ApiMessage.success("博客通过");
    }

    //驳回博客
    @PostMapping("/reviewBlog")
    public ApiMessage<String> reviewBlog(@Validated @RequestBody SendBack sendBack) {
        adminService.reviewBlog(sendBack);
        return ApiMessage.success("博客驳回完成");
    }
    // 6.增加分区
    @GetMapping("/allPartition")
    public ApiMessage<List<Partition>> allPartition() {
        List<Partition> partitions = adminService.allPartition();
        return ApiMessage.success(partitions);
    }

    @PostMapping("/addPartition")
    public ApiMessage<String> addPartition(@Validated @RequestBody Partition partition) {
        adminService.addPartition(partition);
        return ApiMessage.success("分区添加成功");
    }

    @PutMapping("/updatePartition")
    public ApiMessage<String> updatePartition(@Validated @RequestBody Partition partition) {
        adminService.updatePartition(partition);
        return ApiMessage.success("分区更新成功");
    }

    @DeleteMapping("/deletePartition")
    public ApiMessage<String> deletePartition(@RequestParam Integer pid) {
        adminService.deletePartition(pid);
        return ApiMessage.success("分区删除成功");
    }

    // 7.通过反馈表查看用户发送的反馈
    @GetMapping("/getFeedback")
    public ApiMessage<List<UserFeedback>> getFeedback() {
        List<UserFeedback> feedbacks = adminService.getAllFeedbacks();
        return ApiMessage.success(feedbacks);
    }
}
